<template>
	<!-- 分销中心 -->
	<view>
		<view class="head">
			<image src="/static/list/bg2.png" mode=""></image>
			<view class="head_main">
				<view class="text">账户收益（元）</view>
				<view class="numbar  flex-cb">
					<view class="">
						{{info.commission}} 
					</view>
					<view class="button bg-white flex-c" @click="navgeta('Withdrawal')">提现</view>
				</view>
				<view class="commission flex-cb">
					<view class="left">
						<view class="text">累计收益（元）</view>
						<view class="num">{{info.total_commission}}</view>
					</view>
					<view class="center">
						<view class="text">今日收益（元）</view>
						<view class="num">{{info.today_commission}}</view>
					</view>
					<view class="right">
						<view class="text">已提现收益（元）</view>
						<view class="num">{{info.withdraw_commission}}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="list ">
			<view class="list_item flex-cb bg-white" v-for="(item,index) in list" :key="index" @click="navgeta(item.url)" v-if="item.sx == null">
				<view class="text" v-if="index != list.length-2">{{item.text}}</view>
				<button type="" open-type="share" class="text cu-btn  bg-white" v-if="index == 3">{{item.text}}</button>
				<text class="cuIcon-right"></text>
			</view>
		</view>
		<view class="list ">
			<view class="list_item flex-cb bg-white" >
				<view class="text" >{{yqr.text}}</view>
				<text >{{yqr.name?yqr.name:'无'}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user:'',
				info:'',
				yqr:{text:'我的邀请人',name:''},
				list:[
					{
						text:'我的团队',
						url:'team'
					},
					{
						text:'我的商户',
						url:'wode_sh'
					},
					{
						text:'收益记录',
						url:'profit'
					},
					{
						text:'直接分享',
						url:''
					},
					{
						text:'我的推广码',
						url:'tool'
					},
					
				]
			};
		},
		onLoad(e) {
			this.$api.user({},true).then(res=>{
				if(res.code == 200001){
					this.user = res.data
					console.log(res);
				}
			})
			this.$api.commission_infos().then(res=>{
				console.log(res);
				this.info = res.data
			})
			
			this.$api.usersDirect().then(res=>{
				console.log(res);
				if(res.code == 200001){
					this.yqr.name = res.data.phone
				}
			})
			for (let i = 0; i < this.list.length; i++) {
					console.log(111);
				if(this.user.is_agent == 0){
					if(this.list[i].text == '我的商户'){
						console.log(112);
						this.list[i].sx = 1
						
					}
				}
			}
			// if(JSON.parse(e.agent)){
				// uni.setNavigationBarTitle({
				// 	title:'代理中心'
				// })
			// }
		},
		onShow() {
			
		},
		onShareAppMessage(res) {
		    if (res.from === 'button') {// 来自页面内分享按钮
		      console.log(res.target)
		    }
		    return {
		      title: '快来和我一起购物返佣金',
		      path: 'pages/tabbar/index?id='+this.user.id+'&fx=1',
		    }
		},
		methods:{
			navgeta(url){
				uni.navigateTo({
					url:'/pageB/distribution/' + url
				})
			}
		}
	}
</script>

<style lang="scss">
.head{
	padding: 20rpx; 
	image{
		width: 710rpx;
		height: 400rpx;
	}
	.head_main{
		width: 710rpx;
		height: 400rpx;
		padding: 26rpx;
		position: absolute;
		top: 50rpx;
		left: 20rpx;
		color: #FFF;
		.text{
			font-size: 32rpx;
			margin-bottom: 19rpx;
		}
		.numbar{
			height: 84rpx;
			line-height: 84rpx;
			font-size: 60rpx;
			margin-bottom: 48rpx;
			.button{
				width: 120rpx;
				height: 60rpx;
				
				border-radius: 40rpx;
				color: #1CD699;
				font-size: 32rpx;
			}
		}
		.commission{
			text-align: center;
			.text{
				font-size: 28rpx;
				margin-bottom: 15rpx;
			}
			.num{
				font-size: 40rpx;
				height: 56rpx;
				line-height: 56rpx;
			}
		}
		
	}
}
.list{
	padding: 0 20rpx;
	.list_item{
		overflow: hidden;
		height: 100rpx;
		margin-bottom: 20rpx;
		padding: 0 20rpx;
		border-radius: 5rpx;
		.text{
			width: auto;
			font-size: 30rpx;
			font-weight: bold;
			color: #333;
		}
		button{
			flex: 1;
			
		}
		.cu-btn{
			justify-content: start;
			padding: 0;
			position: relative;
			left: 0;
		}
	}
}
</style>
